package com.hexun.busi.share.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hexun.busi.client.StockApiClient;
import com.hexun.busi.common.constants.Constants;
import com.hexun.busi.common.controller.DefaultBaseController;
import com.hexun.busi.common.redis.RedisUtilService;
import com.hexun.busi.common.utils.ValidatorHexunId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @auther: zhoudong
 * @date: 2018/4/23 13:57
 */
@Controller
public class IndexController extends DefaultBaseController {
	private Logger log = LoggerFactory.getLogger(getClass());
	@Resource
	private StockApiClient stockApiClient;

	@RequestMapping(value="",method={RequestMethod.GET})
	public @ResponseBody String home(){

		log.info(" ** 访问首页~~");
		/*JSONObject jsonObject = stockApiClient.recommendUser("27401524",1,11);
		log.info(" -->{}",jsonObject.toJSONString());*/
		// return "Version:1.0";
		return "Version:2.0";
	}

	/**
	 * 跳转url 解决cookie问题
	 * @auther: zhoudong
	 * @date: 2018/5/18 18:06
	 */
	@GetMapping(value="jump")
	public String jump(HttpServletRequest req,ModelMap modelMap, @RequestParam String go_url){
		int i = 1/0;
		try {
			go_url = URLDecoder.decode(go_url, Constants.charset_utf_8);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		Map<String,String> map = ValidatorHexunId.queryHexunInfo(req,log);
		if(map == null) map = new HashMap<>();
		log.info(" ** 跳转地址：{},userId:{}",go_url, map.get("userid"));
		modelMap.put("go_url",go_url);
		return "jump";
	}
}
